jQuery(document).ready(function() {
	//创建JQGRID表格
	var grid = $("#table1").ligerGrid({
        columns: [
			{ display: '角色名', name: 'name',type: 'string',editor: { type: 'string'},width  : 150 },
				{ display: '角色描述', name: 'description',type: 'int',editor: { type: 'string'},width  : 300},
           	 	{ display: '', width  : 200, render: function (rowdata, rowindex, value)
                    {
                        
                      
                        return "<a href='javascript:showRole(" + rowdata.id + ")'>分配权限</a> "; 
                    }
				}
                      ],  usePager: true,pageSize:30,
                      url : sys_context+"/security/role/list.do",
                      width: '100%', height: '98%', checkbox: true,rownumbers:true,           
                      onDblClickRow : function (data, rowindex, rowobj){
                          edit(data);
                       }
                  });
	$("#pageloading").hide();
	
	
});
function showRole(id){
	var url = "/security/role/managerRolePermission.do?roleId="+id;
	
	ShowIframeDialogMax("operate","权限角色管理",url,800,500);
}
//添加
function add(){
	var url = "/security/role/operate/add/0.do";
	
	ShowIframeDialog("operate","添加用户",url,650,300);
}
//编辑
function edit(data){
	var url = "/security/role/operate/edit/"+data.id+".do";
	ShowIframeDialog("operate","修改用户",url,650,300);
}

function del(){
	var manager = $("#table1").ligerGetGridManager(); 
	var rows = manager.getCheckedRows(); 
	
	if (rows.length==0){
		$.dialog.alert('Please select a record');
		return;
	}
    
    var ids = "";
	for(var i = 0;i < rows.length ;i ++) {
	 	if(i!=0){
	 		ids+=",";
	 	}
	 	//获得行数据
	 	ids += rows[i].id;					 	   
	}
	
	getDG().dialog({content: "请确定选择删除数据(Yes或者No)!",width: 250,lock: true,max: false,min: false,
		title:'Confirm Infor',
		button: [
		         {
		             name: 'Yes',
		             callback: function(){
			            $.ajax({
			           	      url: sys_context+"/security/role/delete.do",
			           	      global: false,
			           	      type: "POST",
			           	      dataType: "json",
			           	      data: ({ids : ids}),		     
			           	      success: function(msg){	
			           	    	manager.removeRange(rows);
			           	    	  $.dialog.alert(msg.infor);  		    	
			           	      }
			           	   }
			           	);
		             }
		         },
		         {
		        	   name: 'No',
			           focus: true
		         }             
		     ]
	}).zindex();
	
	
}